// Ofri Keidar 302933981 group 05

package controller;

import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import org.jdom.Document;

import model.apartment.*;
import model.database.DBException;

/**
 * Interface of system's controller. The controller offers transactions that can be done with system's data and safe shutdown.
 */
public interface Controller {

	/**
	 * Returns map of all vacant flats in all the buildings in system- key is flat and value is String
	 * containing flat number in its building and its building address 
	 * Flats are sorted by area in ascending order
	 * @return list of wanted flats
	 * @throws DBException- throws database exception if database encountered a problem
	 */
	public List<Flat> getVacantFlats() throws DBException;
	
	/**
	 * Returns map of all vacant flats with given number of rooms, searching in all system's buildings.
	 * In the map, key is flat and value is String containing flat number in its building and its building address.
	 * Flats are sorted by area in ascending order
	 * @param roomNum- room number to search for
	 * @return list of wanted flats
	 * @throws DBException- throws database exception if database encountered a problem
	 */
	public List<Flat> getVacantFlats(double roomNum) throws DBException;
	
	/**
	 * Returns map of all vacant flats with given number of rooms at given address.
	 * In the map, key is flat and value is String containing flat number in its building and its building address.
	 * Flats are sorted by area in ascending order
	 * @param roomNum- room number to search for
	 * @param stName- name of building's street
	 * @param bldNumber- number of building on street
	 * @return list of wanted flats
	 * @throws DBException- throws database exception if database encountered a problem
	 */
	public List<Flat> getVacantFlats(double roomNum, String stName, int bldNumber)
			throws DBException;
	
	/**
	 * Returns map of all flats at given address- key is flat and value is String 
	 * containing flat number in its building and its building address. 
	 * Flats are sorted by area in ascending order
	 * @param stName- name of building's street
	 * @param bldNumber- number of building on street
	 * @return list of wanted flats
	 * @throws DBException- throws database exception if database encountered a problem
	 */
	public List<Flat> getFlats(String stName, int bldNumber) throws DBException;
	
	/**
	 * Returns map of all penthouses in all buildings in system- key is flat and value is String 
	 * containing flat number in its building and its building address.
	 * Flats are sorted by area in ascending order
	 * @return map of all flats
	 * @throws DBException- throws database exception if database encountered a problem
	 */	
	public List<Flat> getFlats() throws DBException;
	
	/**
	 * Returns map of all penthouses in all buildings in system- key is penthouse and value is String 
	 * containing penthouse number in its building and its building address.
	 * Penthouses are sorted by area in ascending order
	 * @return map of all penthouses
	 * @throws DBException- throws database exception if database encountered a problem
	 */
	public List<Penthouse> getPenthouses() throws DBException;
	
	/**
	 * Returns map of all garden apartments in all buildings in system- key is garden apartment and value is String 
	 * containing garden apartment number in its building and its building address.
	 * Garden apartments are sorted by area in ascending order
	 * @return map of all garden apartments
	 * @throws DBException- throws database exception if database encountered a problem
	 */
	public List<GardenApartment> getGardenApartments() throws DBException;
	
	/**
	 * Returns how many vacant apartments are in system
	 * @return number of vacant apartments in system
	 * @throws DBException- throws database exception if database encountered a problem
	 */
	public int getVacantAprtsNum() throws DBException;
	
	/**
	 * Returns how many vacant apartments are at given address
	 * @param stName street name of wanted address
	 * @param bldNumber building's number on the street
	 * @return number of apartments at given address
	 * @throws DBException- throws database exception if database encountered a problem
	 */
	public int getVacantAprtsNum(String stName, int bldNumber)
			throws DBException;
	
	/**
	 * Parses buildings out of given XML file, and creates the buildings
	 * @param buildingsDocument- XML file holding buildings
	 * @return True if could parse and create buildings, False if not
	 * @throws DBException- throws database exception if database encountered a problem
	 */
	public boolean parseBuildingsFromXML(Document buildingsDocument) throws DBException;

	/**
	 * Gets the type and parameters of each apartment and building's address. Creates a new building with given data.
	 * If could create the building, returns True. Otherwise, returns False  
	 * @param apartmentTypes- list of types for each apartment
	 * @param parameterList- list that holds the parameter map for each apartment 
	 * @param stName- buiding's street name
	 * @param bldNumber- building's number on street
	 * @return True if could add such building, False if not
	 * @throws DBException- throws database exception if database encountered a problem
	 */
	public boolean addBuilding(LinkedList<String> apartmentTypes,
			LinkedList<Map<String, String>> parameterList, String stName,
			int bldNumber) throws DBException;
	
	/**
	 * Updates given resident name of apartment at given address./
	 * If there is no building at given address or no apartment with given number in the building, no update is done 
	 * and False is returned. Otherwise, updates data and True is returned
	 * @param stName- street name of apartment's address
	 * @param bldNum- building number where the apartment is 
	 * @param apartmentNum- apartment's number in the building
	 * @param newResident- new resident name
	 * @return True if updated successfully, False if not
	 * @throws DBException- throws database exception if database encountered a problem
	 */
	public boolean updateResident(String stName, int bldNum, int apartmentNum,
			String newResident) throws DBException;
}